package com.nbsaas.boot.project.controller;

import com.nbsaas.boot.project.api.apis.ProjectTimeApi;
import com.nbsaas.boot.project.api.domain.request.ProjectTimeRequest;
import com.nbsaas.boot.project.api.domain.request.ProjectTimeSearch;
import com.nbsaas.boot.project.api.domain.response.ProjectTimeResponse;
import com.nbsaas.boot.project.api.domain.simple.ProjectTimeSimple;
import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目计时控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/projectTime")
public class ProjectTimeController {


    @Resource
    private ProjectTimeApi projectTimeApi;

    /**
     * 搜索数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("projectTime:search")
    @PostMapping("/search")
    public PageResponse<ProjectTimeSimple> search(@RequestBody ProjectTimeSearch request) {
        return projectTimeApi.search(request);
    }

    /**
     * 列表数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("projectTime:list")
    @PostMapping("/list")
    public ListResponse<ProjectTimeSimple> list(@RequestBody ProjectTimeSearch request) {
        return projectTimeApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("projectTime:create")
    @CreateData
    @PostMapping("/create")
    public ResponseObject<ProjectTimeResponse> create(@RequestBody @Validated(AddOperator.class) ProjectTimeRequest request) {
        return projectTimeApi.create(request);
    }

    /**
     * 修改数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("projectTime:update")
    @UpdateData
    @PostMapping("/update")
    public ResponseObject<ProjectTimeResponse> update(@RequestBody @Validated(UpdateOperator.class) ProjectTimeRequest request) {
        return projectTimeApi.update(request);
    }

    /**
     * 删除数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("projectTime:delete")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) ProjectTimeRequest request) {
        return projectTimeApi.delete(request);
    }

    /**
     * 查看数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("projectTime:view")
    @PostMapping("/view")
    public ResponseObject<ProjectTimeResponse> view(@RequestBody @Validated(ViewOperator.class) ProjectTimeRequest request) {
        return projectTimeApi.view(request);
    }
}